<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/2/7
 * Time: 19:22
 */

namespace app\api\controller;



use think\Db;

class News extends Base
{
    private $user_id;
    private $page;
    private $create_time;
    
    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $this->user_id = input('user_id');
        $this->page = input('page') ? input('page') : 1;
        $this->create_time = date('Y-m-d H:i:s');
        $time = input('time');
        $value = input('value');
        $reqKey = input('reqKey');
        $auth = $this->checkAll($this->user_id,$time,$value,$reqKey);
        if($auth == 112){
            echo json_encode(['status'=>301,'msg'=>$this->otherLogin]);
            exit;
        }elseif($auth == 110){
            echo json_encode(['status' => 302, 'msg' => $this->frost]);
            exit;
        }elseif($auth == 2111){
            echo json_encode(['status' => 303, 'msg' => $this->del]);
            exit;
        }
    }

    /**
     * 获取各类型的派逊天地
     * type：1 品牌资讯  2 荣誉时刻  3 企业资质
     * @return \think\response\Json
     */
    public function newsList(){
        $type = input('type');
        $where['n_type'] = $type;
        $where['n_status'] = 1;
        $list = Db::table('up_news')
            ->field('n_content',true)
            ->where($where)
            ->order('n_top desc,n_time desc')
            ->page($this->page, 10)
            ->select();
        if($list){
            return json(['status' => 200, 'msg' => $list]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    /**
     * 获取各类型的派逊天地
     * type：1 品牌资讯  2 荣誉时刻  3 企业资质
     * @return \think\response\Json
     */
    public function newsInfo(){
        $n_id = input('n_id');
        $where['n_id'] = $n_id;
        $list = Db::table('up_news')
            ->where($where)
            ->find();
        Db::table('up_news')
            ->where($where)
            ->setInc('n_see');
        return json(['status' => 200, 'msg' => $list]);
    }
}